<template>
	<model-page>
		<view class="dataIntDetailList">
			<Card>
				<view class="topic">血糖（mmol/L）</view>
				<view class="row">
					<view class="three_item" v-for="(item,index) in bloodSugarList" :key="index">
						<input type="number" :placeholder="item.placeholder" v-model="postForm[item.props]"/>
						<image src="../../../static/image/alarm/line.png" mode=""></image>
						<text>{{item.title}}</text>
					</view>
				</view>
				<view class="topic">血压（mmHg）</view>
				<view class="row">
					<view class="three_item" v-for="(item,index) in bloodPressList" :key="index">
						<input type="number" :placeholder="item.placeholder" v-model="postForm[item.props]" />
						<image src="../../../static/image/alarm/line.png" mode=""></image>
						<text>{{item.title}}</text>
					</view>
				</view>
				<view class="topic">身高（米）</view>
				<view class="row">
					<view class="three_item">
					<input type="number" placeholder="身高数值" v-model="postForm.weight"/>
					<image src="../../../static/image/alarm/line.png" mode=""></image>
					</view>
				</view>
				<view class="topic">体重（千克）</view>
				<view class="row">
					<view class="three_item">
					<input type="number" placeholder="体重数值" v-model="postForm.height"/>
					<image src="../../../static/image/alarm/line.png" mode=""></image>
					</view>
				</view>
				<view class="topic">体温（°C）</view>
				<view class="row">
					<view class="three_item">
					<input type="number" placeholder="体温数值" v-model="postForm.bodyTemperature"/>
					<image src="../../../static/image/alarm/line.png" mode="" ></image>
					</view>
				</view>
			</Card>
			<view class="btn" @click="submit">
				立即提交
			</view>
		</view>
	</model-page>

</template>

<script setup>
import { reactive, ref } from 'vue';
import {onLoad} from '@dcloudio/uni-app'
import {recordVitalSigns} from '@/api/dataInt.js'
const postForm = reactive({
	elderId:"",
	elderName:"",
	bloodSugarFasting:"",
	bloodSugarPostprandial:"",
	systolic:"",
	diastolic:"",
	pulse:"",
	height:"",
	weight:"",
	bodyTemperature:""
})
const bloodSugarList = ref([
	{
		title:"（空腹）",
		placeholder:"血糖数值",
		props:"bloodSugarFasting"
	},
	{
		title:"（饭后）",
		placeholder:"血糖数值",
		props:"bloodSugarPostprandial"
	}
])
const bloodPressList = ref([
	{
		title:"（舒张压）",
		placeholder:"舒张压数值",
		props:"diastolic"
	},
	{
		title:"（收缩压）",
		placeholder:"收缩压数值",
		props:"systolic"
	},
	{
		title:"（脉搏）",
		placeholder:"脉搏数值",
		props:"pulse"
	}
])
onLoad((option)=>{
	const {elderId,elderName} = option
	postForm.elderId = elderId
	postForm.elderName = elderName
})
// 提交数据录入信息
const submit = async()=>{
	try{
	const {code,data:res,msg} = await recordVitalSigns(postForm)
	if(code === 200){
		if(res){
			uni.showToast({
				icon:"success",
				title:"提交成功",
				duration:1000,
				complete() {
					setTimeout(()=>{
						uni.navigateTo({
							url:"/packageDataInt/pages/index/index"
						})
					},1000)
				}
			})
		}
	}else{
		uni.showToast({
			icon:"error",
			title:msg
		})
	}
	}catch(e){
		//TODO handle the exception
	}
}
</script>

<style lang="less" scoped>
.dataIntDetailList{
.topic{
	font-weight: 500;
	font-size: 32rpx;
	color: #333333;
	margin-bottom: 30rpx;
}
.row{
	display: flex;
	margin-bottom: 30rpx;
}
 .three_item{
	 flex: 1;
	 display: flex;
	 flex-direction: column;
	 align-items: center;
	 justify-content: center;
	 >image{
		 width: 100%;
		 height: 1rpx;
		 margin: 10rpx 0;
	 }
	 >text{
		 font-weight: 400;
		 font-size: 24rpx;
		 color: #999999;
	 }
 }
}
.btn{
	margin-top: 128rpx;
	height: 80rpx;
	background: linear-gradient( 180deg, #74B7FF 0%, #1680F3 100%);
	border-radius: 40rpx;
	text-align: center;
	line-height: 80rpx;
	color: #FFFFFF;
}
</style>
